////////////////////////////////////////////////////////////////////////////////
//
//  MICROSOFT CORPORATION
//  Copyright (c) Microsoft Corporation.
//  All Rights Reserved.
//
//  NOTICE: Microsoft Confidential. Intended for Internal Use Only.
//
////////////////////////////////////////////////////////////////////////////////

package com.msn.beet.tracking.atlas
{

import com.msn.beet.tracking.ITrackModel;

/**
 * Atlas TrackAction for view events, has the capability to update the senders
 * model if values are passed for section and location in the constructor.
 * These updates would occur before the track has been generated.
 */
public class AtlasViewAction extends AtlasTrackAction
{
    include "../../core/Version.as";

    private static const VIEW:String = "view";

    private var section:String;
    private var location:String;

    /**
     * @param id       The action name to be included in the tracking string.
     * @param section  Passing a value will update the Senders model BEFORE
     *                 creating the track.
     * @param location Passing a value will update the Senders model BEFORE
     *                 creating the track.
     */
    public function AtlasViewAction(id:String, section:String = null,
                                    location:String = null):void
    {
        super(id, VIEW);
        this.section = section;
        this.location = location;
    }

    /**
     * Overriding helper to update the model before the string is generated.
     * @param pModel
     * @return
     */
    override public function parseForAtlas(model:ITrackModel):String
    {
        updateModel(model);
        return super.assembleForAtlas(model);
    }

    /**
     * Overriding helper to update the model before the string is generated.
     * @param pModel
     * @return
     */
    override public function parseForAtlasJS(model:ITrackModel):String
    {
        updateModel(model);

        if (model.section == null || model.location == null)
        {
            throw new ReferenceError(
                "Unitialized values in ITrackModel, cannot build track.");
        }

        return super.assembleForAtlasJS(model);
    }

    /**
    * Update the <code>ITrackModel</code> with new section and location.
    */
    protected function updateModel(model:ITrackModel):void
    {
        model.section = this.section || model.section;
        model.location = this.location || model.location;
    }

}

}
